<?php
$Set_Title		= $config_nc->Add.' '.$news_nc->News;
$type			= $func->html_get('type');
if($type=='' || !$news_class->isInt($type) || $type<1 || $type>3){
	$type = 1;
}
if($type==2){
	$Set_Title	= $config_nc->Add.' '.$config_nc->Hotel;
}else if($type==3){
	$Set_Title	= $config_nc->Add.' '.$config_nc->Air_tickets;
}
$Set_Submit		= 'add';
$Id				= $func->html_get('u2');
$ErrorQ 		= $func->GetSession('ErrorQ');
$status 		= $func->GetSession('status');
$sort 			= $func->GetSession('sort');
$image 			= $func->GetSession('image');

$func->DelSession('ErrorQ');
$func->DelSession('name');
$func->DelSession('status');
$func->DelSession('sort');
if($status==''){
	$status = 1;	
}

if($Id!='' && $news_class->isInt($Id)){
	$Row_Result   	= $news_class->GetById($Id);	
	if(is_array($Row_Result)){
		$useradmin 			= $Row_Result[0]['useradmin'];
		$type 				= $Row_Result[0]['type'];
		$status 			= $Row_Result[0]['status'];	
		$sort 				= $Row_Result[0]['sort'];	
		$image 				= $Row_Result[0]['image'];	
		$create_date		= $Row_Result[0]['create_date'];	
		$RowDetail			= $news_detail_class->GetByIdNews(0, 0, $Id);	
	}else{
		$notFound = 0;
	}
	$Set_Submit 	= 'edit' ;
	$Set_Title		= $config_nc->Edit.' '.$news_nc->News;	
	if($type==2){
		$Set_Title	= $config_nc->Edit.' '.$config_nc->Hotel;
	}else if($type==3){
		$Set_Title	= $config_nc->Edit.' '.$config_nc->Air_tickets;
	}
}	

?> 
<div class="dataTables db">
	<div class="dataTables_bar db">
    	<h5 class="title dib"><?php echo $Set_Title;?></h5>        
    </div><!--end dataTables_bar-->
    <div class="themuser db">
    	<?php 
		if(isset($notFound) && $notFound==0){
			echo '<div class="notFound">'.$config_nc->NotFound.'</div>';	
		}else{
		?>             
    	<form class="form-centent" action="<?php echo $WEB_DOMAIN.'/'.$WEB_ADMIN.'/index.php?u1=_news&u2='.$Set_Submit;?>" method="post">
        	<ul class="nd db">
            	<li>
                    <label class="span2 fl">&nbsp;</label>
                    <span class="errorq"><?php if(isset($ErrorQ)){echo $ErrorQ;}?>&nbsp;</span>
                </li>      
                <?php /* $Row_Category   	= $news_type_class->GetByAll();	 ?>
                <li>                
                    <label class="span2 fl"><?php echo $news_nc->Category;?></label>
                    <select name="type">       
                    	<?php 
						if(is_array($Row_Category)){
							$count = count($Row_Category); 
							for($i=0;$i<$count;$i++){
						?>             	
                        <option value="<?php echo $Row_Category[$i]['id_type'];?>" <?php if(isset($type) && $type==$Row_Category[$i]['id_type']){echo 'selected="selected"';}?>><?php echo $Row_Category[$i]['name'];?></option>
                      	<?php
							}
						}
						?>  
                    </select>
                </li>   
				<?php */?>                                      
                <li>
                	<input type="hidden" name="type" value="<?php echo $type;?>" />
                    <label class="span2 fl"><?php echo $news_nc->Image;?></label>
                    <input name="image" type="text" class="span3" value="<?php echo $image;?>" id="ImageUrl" >
                    <input type="button" value="<?php echo $config_nc->Library;?>" id="btnSelectImg" name="" />					
                    <script type="text/javascript">
                        $(document).ready(function () {
                            $("#btnSelectImg").click(function () {
                                var finder = new CKFinder();
                                finder.selectActionFunction = function (fileUrl) {
                                    $('#ImageUrl').val(fileUrl);
                                };
                                finder.popup();
                            });
                        });
                     </script>
                </li>   
                <li>
                    <label class="span2 fl"><?php echo $config_nc->status;?></label>
                    <select name="status">                    	
                        <option value="0" <?php if(isset($status) && $status==0){echo 'selected="selected"';}?>><?php echo $config_nc->status_2;?></option>
                        <option value="1" <?php if(isset($status) && $status==1){echo 'selected="selected"';}?>><?php echo $config_nc->status_1;?></option>
                    </select>
                </li>  
                <?php if(is_array($Row_Language)){?>
                	<?php 
						for($i=0;$i<count($Row_Language);$i++){
							$title = '';
							if(isset($RowDetail) && is_array($RowDetail)){
								for($j=0;$j<count($RowDetail);$j++){
									if($RowDetail[$j]['language']==$Row_Language[$i]['id']){
										$title = $RowDetail[$j]['title'];
									}
								}
							}
					?>
                <li>
                    <label class="span2 fl"><?php echo $news_detail_nc->Title;?> (<?php echo $Row_Language[$i]['name'];?>)</label>
                    <input name="title<?php echo $Row_Language[$i]['id'];?>" type="text" class="span4" value="<?php echo $title;?>">
                </li>     
                	<?php }  ?>
                    <?php 
						for($i=0;$i<count($Row_Language);$i++){
							$content = '';
							if(isset($RowDetail) && is_array($RowDetail)){
								for($j=0;$j<count($RowDetail);$j++){
									if($RowDetail[$j]['language']==$Row_Language[$i]['id']){
										$content = $RowDetail[$j]['content'];
									}
								}
							}		
					?>
                <li>
                    <label class="span2 fl"><?php echo $news_detail_nc->Content;?> (<?php echo $Row_Language[$i]['name'];?>)</label>                    <textarea id="content<?php echo $Row_Language[$i]['id'];?>" name="content<?php echo $Row_Language[$i]['id'];?>" >
                    	<?php echo $content;?>
                    </textarea>
                    <script type="text/javascript">
						CKEDITOR.replace('content<?php echo $Row_Language[$i]['id']?>',{
							filebrowserBrowseUrl : 'public/FCKeditor/ckfinder/ckfinder.html',
							filebrowserImageBrowseUrl : 'public/FCKeditor/ckfinder/ckfinder.html?type=Images',
							filebrowserFlashBrowseUrl : 'public/FCKeditor/ckfinder/ckfinder.html?type=Flash',
							filebrowserUploadUrl : 'public/FCKeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
							filebrowserImageUploadUrl : 'public/FCKeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
							filebrowserFlashUploadUrl : 'public/FCKeditor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash',
						});
					</script>                 
                </li>     
                	<?php }?>
                <?php }?>
                <?php if(isset($create_date)){?>
                <li>
                    <label class="span2 fl"><?php echo $news_nc->Create_date;?></label>
                    <span><?php echo $func->Date_format($create_date);?></span>
                </li>  
                <?php } ?>
            </ul>
            <div class="form-actions db">      
            	<button type="submit"><?php echo $config_nc->Accept;?></button>          
                <input type="hidden" name="id" value="<?php if($Id!=''){ echo $Id;}?>" />
                <a class="dib" href="<?php echo $WEB_DOMAIN.'/'.$WEB_ADMIN.'/index.php?u1=list-news&type='.$type; ?>"><?php echo $config_nc->Cancel;?></a>
            </div><!--end form-actions-->
        </form>
        <?php }?>
        
    </div>
</div><!--end dataTables-->